package revontuli.aMHD;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class ConnFinderAct extends Activity {
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (aMHDApp.mDataManager.getOffline()) {
			startActivity(new Intent(getApplicationContext(), StopListAct.class));
			finish();
		}
		
		setContentView(R.layout.connfinder);
		
	}
	
	
	
	//metody menu
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.connfindermenu, menu);
		return true;
	}
	
	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		if (aMHDApp.mDataManager.getOffline()) { //offline mod
			//5-offline button, 6-online button
			menu.getItem(5).setVisible(false);
			menu.getItem(6).setVisible(true);
			menu.getItem(1).setEnabled(false);
		} else { //online mod
			menu.getItem(5).setVisible(true);
			menu.getItem(6).setVisible(false);
			menu.getItem(1).setEnabled(true);
		}
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.MenuCFFinder:
			startActivity(new Intent(getApplicationContext(), StopFinderAct.class));
			return true;
		case R.id.MenuCFMap:
			startActivity(new Intent(getApplicationContext(), StopMapAct.class));
			return true;
		case R.id.MenuCFLineList:
			startActivity(new Intent(getApplicationContext(), LineListAct.class));
			return true;
		case R.id.MenuCFStopList:
			startActivity(new Intent(getApplicationContext(), StopListAct.class));
			return true;
		case R.id.MenuCFSettings:
			startActivity(new Intent(getApplicationContext(), SettingsAct.class));
			return true;
		case R.id.MenuCFOffline:
			aMHDApp.mDataManager.setOffline(true);
			return true;
		case R.id.MenuCFOnline:
			aMHDApp.mDataManager.setOffline(false);
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}
}
